
/*****
 * 
 * index.js
 * 
*****/

//// 是否有touch事件
var tap = 'click';
$(window).load(function(){
	var isTouch = "ontouchstart" in document ? true : false;
	if(isTouch){
		tap = 'touchstart';
	}else{
		tap = 'click';
	}
	return tap;
});

///banner
$(window).load(function(){
	if($('.pc-ban-bd li').length > 0){
		jQuery('.pc-banner-box').slide({
			mainCell: '.pc-ban-bd ul',
			titCell: '.pc-ban-hd',
			effect: 'fold',
			autoPage: '<a></a>',
			autoPlay: true,
			interTime: 6000,
			delayTime: 500,
			startFun: function(i, c){
				
			}
		});
	}

	if($('.ph-banner-box .swiper-slide').length > 0){
		var phBanSwip = new Swiper ('.ph-banner-box', {
			loop: false,
			effect : 'fade',
			autoplay: {
				delay: 6000,
			},
			pagination: {
			    el: '.ph-ban-hd',
			},
			on:{
		      	init: function(){
		      		var $slide = $(this.slides[this.activeIndex]);
		      		$slide.find('.ban-bg').addClass('scaleUpDown')
		      			.end()
		      			.find('.ban-txt-box').find('.animated').addClass('fadeInUp');
			    }, 
			    slideChangeTransitionStart: function(){ 
			 		var $slide = $(this.slides[this.activeIndex]);
			 		$slide.find('.ban-bg').addClass('scaleUpDown')
			 			.end()
			 			.siblings().find('.ban-bg').removeClass('scaleUpDown');
			 		$slide.find('.ban-txt-box .animated').addClass('fadeInUp')
			 			.end()
			 			.siblings().find('.ban-txt-box .animated').removeClass('fadeInUp');
			    },
			    resize: function(){
			    	phBanSwip.update();
			    } 
		    }
		});
	}

	var len1 = $(".pc-ban-bd li").length;
	var len2 = $(".ph-banner-box .swiper-slide").length;
    if(len1<2){
       $(".pc-ban-hd").hide();
    }
    if(len2<2){
       $(".ph-ban-hd").hide();
    }
})

/// 滚动条

function tipScrollFn(){
	var idArry = [];
	var bdTop = $('.tip-main-bd .bd-box').offset().top;
	for(var i = 0; i < $('.tip-main-bd .side-list li').length; i++){
		var id = $('.tip-main-bd .side-list li').eq(i).find('a').attr('data-href');
		var top = $(id).offset().top - bdTop;
		if(top < 100){
			idArry[i] = id;
			continue;
		}else{
			break;
		}
	}
	var len = idArry.length;
	$('.tip-main-bd .side-list li').eq(len-1).addClass('active').siblings('li').removeClass('active');

}


$('.tip-main-bd .bd-box').mCustomScrollbar({
	mouseWheel:{ 
		scrollAmount: 100 
	},
	scrollInertia: 500,
	advanced:{ 
		updateOnContentResize: true 
	},
	callbacks:{
		onScroll:function(){
			tipScrollFn();
		},
	    whileScrolling:function(){
	    	tipScrollFn();
	    },
	    onTotalScroll: function(){
	    	$('.tip-main-bd .side-list li:last-child').addClass('active').siblings().removeClass('active');
	    }
	}
});

$('.tip-main-bd .side-list a').click(function(event) {
	var id = $(this).attr('data-href');
	$('.tip-main-bd .bd-box').mCustomScrollbar('scrollTo', id);
	$(this).parents('li').addClass('active').siblings().removeClass('active');
});








